/*                          UX-Framework                               
 *                                                                 
 *  iZE Co.,Ltd. Copyright 2009 All rights reserved.          
 *  This file is distributed under the terms of the GNU Lesser 
 *  General Public License, described in file LICENSE.                                     
 */
package jp.ize.ux.components.themes.basic;

// {{{ imports
import jp.ize.ux.components.UXResource;
import jp.ize.ux.components.UXComponentResource;
import jp.ize.ux.geom.UXSize;
import flash.display.MovieClip;
import flash.display.GradientType;
import flash.geom.Matrix;
// }}}
// {{{ class UXButtonResource
/** 
 * UXButtonResource クラス<br>
 * コンポーネントの描画に利用されるリソース情報です。<br>
 *
 * @author		iZE Co., Ltd.<br>
 * @version		$Id: UXButton.hx 20 2009-02-04 08:23:19Z yimai.v $<br>
 */
class UXButtonResource extends UXComponentResource
{
	// {{{ properties

	public var size:UXSize;
	public var color:Int;

	// }}}
	// {{{ public function new( size:UXSize, color:Int, ?res:Dynamic ) : Void
	/**
	* コンストラクタ
	*/
	public function new( size:UXSize, color:Int, ?res:Dynamic ) : Void
	{
		var flag:Bool = true;
		this.color = color;
		if ( res!=null ) flag = false;
		super(res,false);
		this.size = size;
		if ( flag ) {
			setNormal(      Draw(drawNormal) );
			setFocused(     Draw(drawFocused) );
			setHighlighted( Draw(drawHighlighted) );
			setPressed(     Draw(drawPressed) );
			setDisabled(    Draw(drawDisabled) );
			setSelected(    Draw(drawSelected) );
		}
	}

	// }}}
	// {{{ public function drawNormal( mc:MovieClip ) : Void

	dynamic public function drawNormal( mc:MovieClip ) : Void
	{
		var g = mc.graphics;
		g.clear();
		/*
		// {{{ design
		g.beginFill(0xCCCCCC);
		g.moveTo(0,size.height-2);
		g.lineTo(0,5);
		g.curveTo(0,0,5,0);
		g.lineTo(size.width-5,0);
		g.curveTo(size.width,0,size.width,2);
		g.endFill();

		g.beginFill(0x666666);
		g.moveTo(size.width,2);
		g.lineTo(size.width,size.height-5);
		g.curveTo(size.width,size.height,size.width-5,size.height);
		g.lineTo(5,size.height);
		g.curveTo(0,size.height,0,size.height-2);
		g.endFill();

		g.beginFill(color);
		g.drawRoundRect(2,2,size.width-4,size.height-4,5);
		g.endFill();
		// }}}
		*/
		// {{{ design
		var colors:Array<UInt> = [ 0xFFFFFF, color ];
		var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
		var ratios:Array<UInt> = [ 0, 255 ];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox( size.width, size.height, Math.PI/2 );

		g.lineStyle( 1.0, 0x999999 );
		g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
		g.drawRoundRect(0,0,size.width,size.height,10);
		g.endFill();
		// }}}
	}

	// }}}
	// {{{ public function drawFocused( mc:MovieClip ) : Void

	dynamic public function drawFocused( mc:MovieClip ) : Void
	{
		drawNormal(mc);
	}

	// }}}
	// {{{ public function drawHighlighted( mc:MovieClip ) : Void

	dynamic public function drawHighlighted( mc:MovieClip ) : Void
	{
		var g = mc.graphics;
		g.clear();
		/*
		// {{{ design
		g.beginFill(0xCCCCCC);
		g.moveTo(0,size.height-2);
		g.lineTo(0,5);
		g.curveTo(0,0,5,0);
		g.lineTo(size.width-5,0);
		g.curveTo(size.width,0,size.width,2);
		g.endFill();

		g.beginFill(0x666666);
		g.moveTo(size.width,2);
		g.lineTo(size.width,size.height-5);
		g.curveTo(size.width,size.height,size.width-5,size.height);
		g.lineTo(5,size.height);
		g.curveTo(0,size.height,0,size.height-2);
		g.endFill();

		var rr:Int = ((color&0xFF0000)>>16) + 0x20;
		var gg:Int = ((color&0x00FF00)>>8)  + 0x20;
		var bb:Int = (color&0x0000FF)       + 0x20;
		rr = rr>=0xFF ? 0xFF : rr;
		gg = gg>=0xFF ? 0xFF : gg;
		bb = bb>=0xFF ? 0xFF : bb;
		var newcolor:Int = (rr<<16) | (gg<<8) | bb;
		g.beginFill(newcolor);
		g.drawRoundRect(2,2,size.width-4,size.height-4,5);
		g.endFill();
		// }}}
		*/
		// {{{ design
		var rr:Int = ((color&0xFF0000)>>16) + 0x20;
		var gg:Int = ((color&0x00FF00)>>8)  + 0x20;
		var bb:Int = (color&0x0000FF)       + 0x20;
		rr = rr>=0xFF ? 0xFF : rr;
		gg = gg>=0xFF ? 0xFF : gg;
		bb = bb>=0xFF ? 0xFF : bb;
		var newcolor:Int = (rr<<16) | (gg<<8) | bb;
		var colors:Array<UInt> = [ 0xFFFFFF, newcolor ];
		var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
		var ratios:Array<UInt> = [ 0, 255 ];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox( size.width, size.height, Math.PI/2 );

		g.lineStyle( 1.0, 0x999999 );
		g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
		g.drawRoundRect(0,0,size.width,size.height,10);
		g.endFill();
		// }}}
	}

	// }}}
	// {{{ public function drawPressed( mc:MovieClip ) : Void

	dynamic public function drawPressed( mc:MovieClip ) : Void
	{
		var g = mc.graphics;
		g.clear();
		/*
		// {{{ design
		g.beginFill(0x666666);
		g.moveTo(0,size.height-2);
		g.lineTo(0,5);
		g.curveTo(0,0,5,0);
		g.lineTo(size.width-5,0);
		g.curveTo(size.width,0,size.width,2);
		g.endFill();

		g.beginFill(0xCCCCCC);
		g.moveTo(size.width,2);
		g.lineTo(size.width,size.height-5);
		g.curveTo(size.width,size.height,size.width-5,size.height);
		g.lineTo(5,size.height);
		g.curveTo(0,size.height,0,size.height-2);
		g.endFill();

		var rr:Int = ((color&0xFF0000)>>16) - 0x20;
		var gg:Int = ((color&0x00FF00)>>8)  - 0x20;
		var bb:Int = (color&0x0000FF)       - 0x20;
		rr = rr>=0 ? rr : 0;
		gg = gg>=0 ? gg : 0;
		bb = bb>=0 ? bb : 0;
		var newcolor:Int = (rr<<16) | (gg<<8) | bb;
		g.beginFill(newcolor);
		g.drawRoundRect(2,2,size.width-4,size.height-4,5);
		g.endFill();
		// }}}
		*/
		// {{{ design
		var rr:Int = ((color&0xFF0000)>>16) - 0x20;
		var gg:Int = ((color&0x00FF00)>>8)  - 0x20;
		var bb:Int = (color&0x0000FF)       - 0x20;
		rr = rr>=0 ? rr : 0;
		gg = gg>=0 ? gg : 0;
		bb = bb>=0 ? bb : 0;
		var newcolor:Int = (rr<<16) | (gg<<8) | bb;
		var colors:Array<UInt> = [ newcolor, newcolor ];
		var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
		var ratios:Array<UInt> = [ 0, 255 ];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox( size.width, size.height, Math.PI/2 );

		g.lineStyle( 1.0, 0x999999 );
		g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
		g.drawRoundRect(0,0,size.width,size.height,10);
		g.endFill();
		// }}}
	}

	// }}}
	// {{{ public function drawDisabled( mc:MovieClip ) : Void

	dynamic public function drawDisabled( mc:MovieClip ) : Void
	{
		drawPressed(mc);
		/*
		// {{{ design
		var g = mc.graphics;
		g.clear();
		g.beginFill(0x666666);
		g.moveTo(0,size.height-2);
		g.lineTo(0,5);
		g.curveTo(0,0,5,0);
		g.lineTo(size.width-5,0);
		g.curveTo(size.width,0,size.width,2);
		g.endFill();

		g.beginFill(0xCCCCCC);
		g.moveTo(size.width,2);
		g.lineTo(size.width,size.height-5);
		g.curveTo(size.width,size.height,size.width-5,size.height);
		g.lineTo(5,size.height);
		g.curveTo(0,size.height,0,size.height-2);
		g.endFill();

		var rr:Int = ((color&0xFF0000)>>16) - 0x20;
		var gg:Int = ((color&0x00FF00)>>8)  - 0x20;
		var bb:Int = (color&0x0000FF)       - 0x20;
		rr = rr>=0 ? rr : 0;
		gg = gg>=0 ? gg : 0;
		bb = bb>=0 ? bb : 0;
		var newcolor:Int = (rr<<16) | (gg<<8) | bb;
		g.beginFill(newcolor);
		g.drawRoundRect(2,2,size.width-4,size.height-4,5);
		g.endFill();
		// }}}
		*/
	}

	// }}}
	// {{{ public function drawSelected( mc:MovieClip ) : Void

	dynamic public function drawSelected( mc:MovieClip ) : Void
	{
	}

	// }}}
}
// }}}
